package com.cskaoyan.wordmemorize.controller.app;

import com.cskaoyan.wordmemorize.auth.SaUserCheckPermission;
import com.cskaoyan.wordmemorize.auth.StpKit;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.dto.admin.VocDTO;
import com.cskaoyan.wordmemorize.dto.app.DisplayBookVocDTO;
import com.cskaoyan.wordmemorize.dto.app.DisplayChapterDTO;
import com.cskaoyan.wordmemorize.request.AppVocPageRequest;
import com.cskaoyan.wordmemorize.service.VocService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * APP端单词控制器
 * 提供单词相关的接口服务
 */
@RestController
@RequestMapping("user/voc")
public class VocController {

    @Resource
    private VocService vocService;

    /**
     * 获取书籍单词列表(无章节版)
     *
     * @param pageRequest 查询参数
     * @return 单词列表分页数据
     */
    @GetMapping("book/display")
    public Result<PageDTO<DisplayBookVocDTO>> getBookWords(AppVocPageRequest pageRequest) {
        // 获取当前登录用户ID
        Long userId = StpKit.USER.getLoginIdAsLong();
        pageRequest.setUserId(userId.toString());

        // 调用服务层获取数据
        PageDTO<DisplayBookVocDTO> result = vocService.getDisplayBookVocsInfo(pageRequest);
        return Result.ok(result);
    }

    /**
     * 获取书籍单词列表(有章节版)
     *
     * @param pageRequest 查询参数
     * @return 章节列表分页数据
     */
    @GetMapping("book/chapter/display")
    public Result<PageDTO<DisplayChapterDTO>> getBookChapters(AppVocPageRequest pageRequest) {
        // 获取当前登录用户ID
        Long userId = StpKit.USER.getLoginIdAsLong();
        pageRequest.setUserId(userId.toString());

        // 调用服务层获取数据
        PageDTO<DisplayChapterDTO> result = vocService.getDisplayBookChapterVocsInfo(pageRequest);
        return Result.ok(result);
    }

    /**
     * 获取单词详情
     *
     * @param vocId 单词ID
     * @return 单词详情数据
     */
    @GetMapping("detail/{vocId}")
//    @SaUserCheckPermission("")
    public Result<VocDTO> getVocDetail(@PathVariable Long vocId) {
        // 获取当前登录用户ID
        Long userId = StpKit.USER.getLoginIdAsLong();

        // 调用服务层获取单词详情
        VocDTO vocDetail = vocService.getVocDetail(vocId, userId);
        return Result.ok(vocDetail);
    }



}